<%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic" %>
<%@ taglib uri="http://struts.apache.org/tags-tiles" prefix="tiles" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>个人设置</title>
<link href="../css/mngMain.css" type="text/css" rel="stylesheet" />

<script type="text/javascript" src="../js/jquery.js"></script>
<script type="text/javascript">
      function hideAll(){
         $("#pwd_suc").hide();
         $("#pwd_fail").hide();
         $("#contactPerson_suc").hide();
         $("#contactPerson_fail").hide();
         $("#telphone_suc").hide();
         $("#telphone_fail").hide();
         $("#email_suc").hide();
         $("#email_fail").hide();
      }

      $(function(){
             hideAll();
             $("#editPwd_btn").click(function(){
                  hideAll();
                  $("#old_pwd").attr("value","");
                  $("#new_pwd").attr("value","");
                  $("#new_pwd2").attr("value","");
                  $("#editPwd_table").toggle();
                  return false;  
             }); 
             
             $("#cancelPwd_btn").click(function(){
                  hideAll();                
                  $("#editPwd_table").hide();
                  return false;  
             });   
             
             $("#contactPerson_btn").click(function(){
                 hideAll();
                 $("#contactPerson_input").attr("value","");
                 $("#contactPerson_span").toggle();
                 return false;
             });
             
             $("#telphone_btn").click(function(){
                 hideAll();
                 $("#telphone_input").attr("value","");
                 $("#telphone_span").toggle();
                 return false;
             });
             
             $("#email_btn").click(function(){
                 hideAll();
                 $("#email_input").attr("value","");
                 $("#email_span").toggle();
                 return false;
             });
             
             $(".cancel_btn").click(function(){
                 hideAll();
                 $(this).parent().hide();
                 return false;
             });
             
             $("#password_confirm").click(function(){
                var old_pwd=$("#old_pwd").attr("value");
                var new_pwd=$("#new_pwd").attr("value");
                var new_pwd2=$("#new_pwd2").attr("value");
                if(new_pwd!=new_pwd2){
                    alert("你两次输入的新密码不一致");
                }else  if((new_pwd==undefined)||(new_pwd==null)){
                   alert("密码不能为空");                             
                }
                else if(new_pwd.length<6){
                   alert("密码需大于6个字符"); 
                }
                else if(new_pwd.length>15){
                   alert("密码需小于15个字符"); 
                }
                else{
                    $.get("../admin/updatePassword.do",{oldPassword:old_pwd,newPassword:new_pwd},
                           function(getText){
                                $("#editPwd_table").hide();
                                if(getText=="success"){
                                    $("#pwd_suc").show(); 
                                }else{
                                    $("#pwd_fail").show();
                                }                           
                           });
                }
             })
             
             $("#contactPerson_confirm").click(function(){
                 var contact_Person=$("#contactPerson_input").attr("value");
                 $.get("../admin/updateContactPerson.do",{contactPerson:contact_Person},
                           function(getText){
                                $("#contactPerson_confirm").parent().hide();
                                if(getText=="success"){
                                    if((contact_Person!=undefined)&&(contact_Person!=null))
                                          $("#contactPerson_show").html(contact_Person);
                                    else
                                          $("#contactPerson_show").html("未指定");        
                                    $("#contactPerson_suc").show(); 
                                }else{
                                    $("#contactPerson_fail").show();
                                }                           
                      });                                            
             });
             
             $("#telphone_confirm").click(function(){
                 var telphone=$("#telphone_input").attr("value");
                 $.get("../admin/updateTelephone.do",{telphone:telphone},
                           function(getText){
                                $("#telphone_confirm").parent().hide();
                                if(getText=="success"){
                                    if((telphone!=undefined)&&(telphone!=null))
                                           $("#telphone_show").html(telphone);
                                    else
                                          $("#telphone_show").html("未指定");          
                                    $("#telphone_suc").show(); 
                                    
                                }else{
                                    $("#telphone_fail").show();
                                }                           
                      });                                            
             });
             
             $("#email_confirm").click(function(){
                 var mail=$("#email_input").attr("value");                
                 $.get("../admin/updateEmail.do",{email:mail},
                           function(getText){
                                $("#email_confirm").parent().hide();
                                if((mail!=undefined)&&(mail!=null))
                                         $("#email_show").html(mail);
                                else
                                          $("#email_show").html("未指定");   
                                if(getText=="success"){
                                    $("#email_suc").show(); 
                                }else{
                                    $("#email_fail").show();
                                }                           
                      });                                            
             });
             
             
      });
</script>

</head>

<body>
<div class="controlBox">
	<%@include file="../admin_top.jsp" %>
	<div class="mngMain">
		<div class="mngLeft">
		  <%@include file="../admin_menu.jsp" %>
		</div>
		<div class="mngRight">
			<div class="mngRightContainer">
				<div class="mngRightContainerT">个人设置</div>
				<div class="mngRightContainerM">
					<table class="addUser">
						<tr>
							<th>用户名：</th>
						  	<td><bean:write name="user" property="username"/></td>
						</tr>
						<tr id="pwd_suc"><td></td><td>密码修改成功</td></tr>
						<tr id="pwd_fail"><td></td><td>你输入的原密码不正确</td></tr>
						<tr>
							<th>密码：</th>
							<td>******&nbsp;&nbsp;&nbsp;&nbsp;<a href="#" id="editPwd_btn">修改密码</a></td>
						</tr>
						<tbody style="display:none" id="editPwd_table">
						<tr>
							<th>原密码：</th>
							<td><input type="password" id="old_pwd"/></td>
						</tr>
						<tr>
							<th>新密码：<br /></th>
							<td><input type="password" id="new_pwd"/></td>
						</tr>
						<tr>
							<th>确认密码：</th>
							<td><input type="password" id="new_pwd2"/><a href="#" id="password_confirm">确定</a>&nbsp;&nbsp;&nbsp;&nbsp;<a href="#" id="cancelPwd_btn">取消</a></td>
						</tr>
						</tbody>
						
						<logic:notEqual name="user" property="type" value="0">
						    <tr id="contactPerson_suc"><td>联系人设置成功</td></tr>
						    <tr id="contactPerson_fail"><td>联系人设置失败</td></tr>
							<tr>
								<th>联系人：</th>
								<logic:notEmpty name="user" property="contactPerson" >
								   <td><span id="contactPerson_show"><bean:write name="user" property="contactPerson"/></span> &nbsp;&nbsp;&nbsp;&nbsp;<a href="#" id="contactPerson_btn">修改</a>
								       <span style="display:none" id="contactPerson_span"><input type="text" id="contactPerson_input"/><a href="#" id="contactPerson_confirm">确定</a>&nbsp;&nbsp;&nbsp;&nbsp;<a href="#" class="cancel_btn">取消</a></span>
								   </td>
							    </logic:notEmpty>
							    <logic:empty name="user" property="contactPerson" >
								   <td><span id="contactPerson_show">未指定</span>&nbsp;&nbsp;&nbsp;&nbsp;<a href="#" id="contactPerson_btn">添加</a>
								       <span style="display:none" id="contactPerson_span"><input type="text" id="contactPerson_input"/><a href="#" id="contactPerson_confirm">确定</a>&nbsp;&nbsp;&nbsp;&nbsp;<a href="#" class="cancel_btn">取消</a></span>
								   </td>
							    </logic:empty>							    
							</tr>
							<tr id="telphone_suc"><td>联系电话设置成功</td></tr>
							<tr id="telphone_fail"><td>联系电话设置成功</td></tr>
							<tr>
								<th>联系电话：</th>							
								<logic:notEmpty name="user" property="telphone" >
								   <td><span id="telphone_show"><bean:write name="user" property="telphone"/></span> &nbsp;&nbsp;&nbsp;&nbsp;<a href="#" id="telphone_btn">修改</a>
								       <span style="display:none" id="telphone_span"><input type="text" id="telphone_input"/><a href="#" id="telphone_confirm">确定</a>&nbsp;&nbsp;&nbsp;&nbsp;<a href="#" class="cancel_btn">取消</a></span>
								   </td>
							    </logic:notEmpty>
							    <logic:empty name="user" property="telphone" >
								   <td><span id="telphone_show">未指定</span> &nbsp;&nbsp;&nbsp;&nbsp;<a href="#" id="telphone_btn">添加</a>
								       <span style="display:none" id="telphone_span"><input type="text" id="telphone_input"/><a href="#" id="telphone_confirm">确定</a>&nbsp;&nbsp;&nbsp;&nbsp;<a href="#" class="cancel_btn">取消</a></span>
								   </td>
							    </logic:empty>
							</tr>
							<tr id="email_suc"><td>电子邮件设置成功</td></tr>
							<tr id="email_fail"><td>电子邮件设置成功</td></tr>
							<tr>
								<th>电子邮件：</th>
								<logic:notEmpty name="user" property="email" >
								   <td><span id="email_show"><bean:write name="user" property="email"/></span> &nbsp;&nbsp;&nbsp;&nbsp;<a href="#" id="email_btn">修改</a>
								       <span style="display:none" id="email_span"><input type="text" id="email_input"/><a href="#" id="email_confirm">确定</a>&nbsp;&nbsp;&nbsp;&nbsp;<a href="#" class="cancel_btn">取消</a></span>
								   </td>
							    </logic:notEmpty>
							    <logic:empty name="user" property="email" >
								   <td><span id="email_show">未指定</span> &nbsp;&nbsp;&nbsp;&nbsp;<a href="#" id="email_btn">添加</a>
								       <span style="display:none" id="email_span"><input type="text" id="email_input"/><a href="#" id="email_confirm">确定</a>&nbsp;&nbsp;&nbsp;&nbsp;<a href="#" class="cancel_btn">取消</a></span>
								   </td>
							    </logic:empty>
							</tr>
						</logic:notEqual>
					</table>
				</div>
			</div>
		</div>
	</div>
	<div class="mngBottom">
		<div class="mngLine"></div>
	</div>
</div>
</body>
</html>
